/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package monkey;

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Sphere;

/**
 *
 * @author mathyas
 */

/*
 * Mostra o espaço tridimensional com eixos, planos e objetos
 * para o usuário se familiarizar com o sistema.
 */
public class Space3DMonkey extends SimpleApplication {
    
    private Geometry geometryBox;
    private Geometry eixoX;
    private Geometry eixoY;
    private Geometry eixoZ;
    private Geometry planoXY;
    private Geometry planoXZ;
    private Geometry planoYZ;

    @Override
    public void simpleInitApp() {
        // ativa janela do game apenas com mouse-arrasta
        flyCam.setDragToRotate(true);
        
        //Altera velocidade da camera
        flyCam.setMoveSpeed(5f);
        
        Sphere s = new Sphere(10, 10, 0.1f);
        geometryBox = new Geometry("Box", s);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", ColorRGBA.Red);
        geometryBox.setMaterial(mat);
        rootNode.attachChild(geometryBox);
        
        Box bx = new Box(1000, 0.01f, 0.01f);
        Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        eixoX = new Geometry("EixoX", bx);
        mat2.setColor("Color", ColorRGBA.Cyan);
        eixoX.setMaterial(mat2);
        rootNode.attachChild(eixoX);
        
        Box by = new Box(0.01f, 1000, 0.01f);
        Material mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        eixoY = new Geometry("EixoY", by);
        mat3.setColor("Color", ColorRGBA.Cyan);
        eixoY.setMaterial(mat3);
        rootNode.attachChild(eixoY);
        
        Box bz = new Box(0.01f, 0.01f, 1000);
        Material mat4 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        eixoZ = new Geometry("EixoZ", bz);
        mat4.setColor("Color", ColorRGBA.Cyan);
        eixoZ.setMaterial(mat4);
        rootNode.attachChild(eixoZ);
        
        Box xy = new Box(2, 2, 0.01f);
        Material mat5 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        planoXY = new Geometry("planoXY", xy);
        mat5.setColor("Color", ColorRGBA.Blue);
        planoXY.setMaterial(mat5);
        
        Box xz = new Box(2, 0.01f, 2);
        Material mat6 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        planoXZ = new Geometry("planoXZ", xz);
        mat6.setColor("Color", ColorRGBA.Red);
        planoXZ.setMaterial(mat6);
        
        Box yz = new Box(0.01f, 2, 2);
        Material mat7 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        planoYZ = new Geometry("planoYZ", yz);
        mat7.setColor("Color", ColorRGBA.Orange);
        planoYZ.setMaterial(mat7);

    }
    
    public void setBoxCoord(float x, float y, float z) {
        geometryBox.setLocalTranslation(x, y, z);
    }
    
    /*
     * Insere e remove os eixos
     */
    public void exibirEixo(char eixo, boolean exibir) {
        
        if(eixo == 'x') {
            if(exibir && !rootNode.hasChild(eixoX))
                rootNode.attachChild(eixoX);
            if(!exibir && rootNode.hasChild(eixoX))
                 rootNode.detachChild(eixoX);
        }
        else if(eixo == 'y') {
            if(exibir && !rootNode.hasChild(eixoY))
                rootNode.attachChild(eixoY);
            if(!exibir && rootNode.hasChild(eixoY))
                 rootNode.detachChild(eixoY);
        }
        else if(eixo == 'z') {
            if(exibir && !rootNode.hasChild(eixoZ))
                rootNode.attachChild(eixoZ);
            if(!exibir && rootNode.hasChild(eixoZ))
                 rootNode.detachChild(eixoZ);
        }
        
        rootNode.updateGeometricState();
    }
    
     public void exibirPlanoXY(boolean exibir) {
         if(exibir && !rootNode.hasChild(planoXY))
             rootNode.attachChild(planoXY);
         if(!exibir && rootNode.hasChild(planoXY))
             rootNode.detachChild(planoXY);
     }
     
     public void exibirPlanoXZ(boolean exibir) {
         if(exibir && !rootNode.hasChild(planoXZ))
             rootNode.attachChild(planoXZ);
         if(!exibir && rootNode.hasChild(planoXZ))
             rootNode.detachChild(planoXZ);
     }
     
     public void exibirPlanoYZ(boolean exibir) {
         if(exibir && !rootNode.hasChild(planoYZ))
             rootNode.attachChild(planoYZ);
         if(!exibir && rootNode.hasChild(planoYZ))
             rootNode.detachChild(planoYZ);
     }
     
     public static void main(String[] args) {
        new Space3DMonkey().start();
    }
    
}
